package lines.gameengine;

/**
 * Represents cell of the field
 * 
 * @author vpotapenko
 */
public class Cell implements ICell {

    private final FieldPoint point;

    private IBall ball;


    /**
     * Creates empty cell with initialized point of the cell. Vertical and horizontal coordinates
     * should be valid, it doesn't check in the constructor.
     *  
     * @param x horizontal coordinate of the new cell
     * @param y vertical coordinate of the new cell
     */
    public Cell(int x, int y) {
        point = new FieldPoint(x, y);
    }

    /**
     * Returns point of the cell
     * @return point of the cell
     */
    @Override
    public FieldPoint getPoint() {
        return point;
    }

    /**
     * Returns ball of the cell or <code>null</code> if this cell doesn't have one
     * 
     * @return ball of the cell or <code>null</code>
     */
    @Override
    public IBall getBall() {
        return ball;
    }

    /**
     * Sets a new ball in the field
     * @param ball a new ball
     */
    public void setBall(IBall ball) {
        this.ball = ball;
    }

    /**
     * Clear the cell from a ball if it has this one
     */
    public void clear() {
        ball = null;
    }

    @Override
    public boolean isEmpty() {
        return ball == null;
    }
}
